/**
 * Created by Administrator on 2018/11/2.
 */
var nowBrCode;

$CertusJsonAjax.ajax("findBrCode",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId(),
},function(res){
    if(res.data){
        nowBrCode = res.data;

        $$scope.applyInfo = {};
        purchaseStepEntity = {
            "processInstanceId": $CertusJsonAjax.getProInstanceId()
        }
        $$scope.submitter = {};
        $$scope.submmitData = {};
        $$scope.submmitData.purchaseStepEntity = {
            "processInstanceId": $CertusJsonAjax.getProInstanceId(),
            "stepInstanceId": $CertusJsonAjax.getStepInstanceId(),
        }
        $$scope.select = {};
        $$scope.disUploadPurchaseFile = function(){
            $$scope.modalContent = {};

            $$scope.modalContent = eval($$scope.headerMap.attachmentFilestr);

            // $$scope.modalContent = data.data;
            $$scope.ok = function () {
                $modalInstance.close(); // 点击确认后关闭弹窗
            };
            $$scope.cancel = function () {
                $modalInstance.dismiss('cancel'); // 点击取消后撤销模态框
            }
            var modalContent = $$scope.modalContent;

            $fileListService.openConfirmWindow("提示", modalContent).then(function (res) {
            });
        }

        $$scope.getsssbbb = function(bb){
            ;
            //starting denied sentback others completed
            if(bb == "starting"){
                return "正在进行中";
            }else if(bb == "denied"){
                return "否决";
            }else if(bb == "sentback"){
                return "被退";
            }else if(bb == "others"){
                return "关闭";
            }else if(bb == "completed"){
                return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
            return "待办";
        }

        $CertusFormAjax.ajax("queryByBrcode", {
            "brCode": nowBrCode
        }, function (res) {
            if (res.data) {
                $$scope.headerMap = res.data.headerMap;
                $$scope.processs = res.data.processs;
                brCode = res.data.headerMap.brCode;
                // purchaseStepEntity.buyingRequisitionCode = res.data.headerMap.brCode;
                $$scope.submmitData.purchaseStepEntity.buyingRequisitionCode = res.data.headerMap.brCode;
                $$scope.submmitData.purchaseStepEntity.projId = res.data.headerMap.projId;
                var datas = res.data.buyings;
                var priceOption1 = {
                    lang: 'zh-cn',
                    ajaxLoad: false,
                    // loadURL:'url',
                    exportFileName: '采购单条目信息',
                    datas: datas,
                    columns: proc1Columns,
                    extraWidth: 20,
                    gridContainer: 'purchaselogContainer',
                };
                aboveGrid = $.fn.dlshouwen.grid.init(priceOption1);
                aboveGrid.load();

                //初始化 报价 文件 数据
                if (datas) {
                    for (var i in datas) {
                        if (datas[i].biCode) {
                            bqArray[datas[i].biCode] = datas[i].buyingQuoteItemEntities;
                        }
                    }
                    //初始化 历史报价 文件 数据
                    for (var i in datas) {
                        if (datas[i].biCode) {
                            oldBqArray[datas[i].biCode] = datas[i].inventorQuoteItemEntities;
                        }
                    }
                }

                var prcListOption = {
                    lang: 'zh-cn',
                    ajaxLoad: false,
                    // loadURL:'url',
                    exportFileName: '资产信息',
                    datas: res.data.inventors,
                    columns: prcListColumns,
                    gridContainer: 'assetslogContainer',
                    tools: '',
                    pageSize: 10,
                    extraWidth: 20,
                    pageSizeLimit: [10, 15, 20]
                };
                belowGrid = $.fn.dlshouwen.grid.init(prcListOption);
                belowGrid.load();

                var endOption = {
                    lang: 'zh-cn',
                    ajaxLoad: false,
                    // loadURL:'url',
                    exportFileName: '结果清单',
                    datas: [],
                    columns: endColumns,
                    gridContainer: 'endContainer',
                    // toolbarContainer: 'endToolBarContainer',
                    tools: '',
                    pageSize: 10,
                    extraWidth: 20,
                    pageSizeLimit: [10, 15, 20]
                };
                endGrid = $.fn.dlshouwen.grid.init(endOption);
                endGrid.load();
            }
        });
    }
})

$$scope.purchaseShut = function(){
    $CertusJsonAjax.ajax("purchaseShut",{
        "processInstanceId": $CertusJsonAjax.getProInstanceId(),
        "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
    },function(res){
        if(res.data == "success"){
            history.back();
        }
    })
}

